local yinjie = fk.CreateSkill {
  name = "th_yinjie",
}

yinjie:addEffect(fk.Damaged, {
  anim_type = "masochism",
  trigger_times = function (self, event, target, player, data)
    return data.damage
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = Fk:translate('#th_yinjie-invoke')
    if #player:getPile('th_yinjie_ye') >= 1 then
      prompt = prompt .. Fk:translate('#th_faxiang-invoke_damage')
    end
    return player.room:askToSkillInvoke(player, {
      skill_name = yinjie.name,
      prompt = prompt
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile('th_yinjie_ye', room:getNCards(1), true, yinjie.name, player)
    local cards = player:getPile('th_yinjie_ye')
    if #cards < 2 then return end
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPutIntoDiscardPile, yinjie.name, nil, nil, player)
    local colors = {}
    for _, cid in ipairs(cards) do
      table.insertIfNeed(colors, Fk:getCardById(cid).color)
    end
    local x = 3 - #colors
    local targets = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      skill_name = yinjie.name,
      cancelable = false, 
      prompt = '#th_yinjie-damage:::' .. x
    })
    if x < 1 or #targets == 0 then return end
    room:doIndicate(player, targets)
    room:damage{
      from = player,
      to = targets[1],
      damage = x,
      damageType = fk.ThunderDamage,
      skillName = yinjie.name
    }
  end
})

yinjie:addTest(function(room, me)
  local comp2 = room.players[2]
  FkTest.RunAddSkills(me, yinjie.name)

  FkTest.setNextReplies(me, {
    "1", "1",
    FkTest.replyChoosePlayer({ comp2 })
  })
  --- test: comp2 对 me 造成 2 点 伤害
  --- 期望：me摸两张牌，对comp2造成2点伤害
  FkTest.runInRoom(function ()
    room:moveCardTo({ 1, 2 }, Card.DrawPile) -- 控顶
    room:damage{
      from = comp2,
      to = me,
      damage = 2,
    }
  end)

  lu.assertEquals(me:getHandcardNum(), 2)
  lu.assertEquals(comp2:getLostHp(), 2)
end)

Fk:loadTranslationTable{
  ["th_yinjie"] = "阴劫",
  [":th_yinjie"] = "当你受到1点伤害后，你可以将牌堆顶一张牌置于你的武将牌上称为“业”，若你有至少两张“业”，你获得所有“业”并对一名其他角色造成X点雷电伤害（X为3-“业”颜色数）。",

  ["#th_yinjie-invoke"] = "阴劫：你可以将牌堆顶一张牌置于你的武将牌上称为“业”",
  ["#th_faxiang-invoke_damage"] = "，然后对一名其他角色造成伤害",

  ["#th_yinjie-damage"] = "阴劫：请对一名其他角色造成%arg点雷电伤害",

  ["th_yinjie_ye"] = "业",
}

return yinjie